/**
 * 找最左上角块
 */
public class Leetcode419 {
    public int countBattleships(char[][] board) {
        int battleships = 0;
        int columnNumber = board.length;
        int rowNumber = -1;
        for (int column = 0; column < columnNumber; column++) {
            if (rowNumber == -1) {
                rowNumber = board[column].length;
            }
            for (int row = 0; row < rowNumber; row++) {
                if (board[column][row] == 'X') {
                    if (column > 0 && board[column - 1][row] == 'X') {
                        continue;
                    }
                    if (row > 0 && board[column][row - 1] == 'X') {
                        continue;
                    }
                    battleships++;
                }
            }
        }
        return battleships;
    }
}
